package org.puppet.demo.mario;

import org.puppet.game.control.AbstractController;
import org.puppet.game.control.PuppetUpdateController;

public class MarioUpdateController extends AbstractController {

	private Mario mario;

	private float minY = 0;
	private float maxY = 160f;

	private float minX = 0;
	private float maxX = 319f;
	
	public MarioUpdateController(Mario mario) {
		this.mario = mario;
	}

	public boolean action(Integer eventId, Object e) {

		if (mario.x < minX) {
			mario.x = minX;
			if (mario.isWalking()) {
				mario.stand();
			}
		}
		if (mario.x > maxX) {
			mario.x = maxX;
			if (mario.isWalking()) {
				mario.stand();
			}
		}
		if (mario.y > maxY) {
			mario.y = maxY;
			mario.stand();
		} else {
			minY=mario.getHeight();
			if (mario.y < minY) {
				mario.y = minY;
				mario.vY = 0.0f;
			}
		}

		return true;
	}

	public int[] lookEvent() {
		return new int[]{PuppetUpdateController.IN_WORLD};
	}

}
